package com.audible.library.domain.beans;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * This is a lightweight persistence domain object representing user_audio_book_rating table in the database.
 *
 * @author Jigar Shah
 * @version 0.1
 */
@Entity
@Table(name = "user_audio_book_rating")
@NamedQueries({
    @NamedQuery(name = "UserAudioBookRating.findAll", query = "SELECT u FROM UserAudioBookRating u"),
    @NamedQuery(name = "UserAudioBookRating.findByUserAudioBookUserProfileId", query = "SELECT u FROM UserAudioBookRating u WHERE u.userAudioBookRatingPK.userAudioBookUserProfileId = :userAudioBookUserProfileId"),
    @NamedQuery(name = "UserAudioBookRating.findByUserAudioBookAudioBookId", query = "SELECT u FROM UserAudioBookRating u WHERE u.userAudioBookRatingPK.userAudioBookAudioBookId = :userAudioBookAudioBookId"),
    @NamedQuery(name = "UserAudioBookRating.findByOverall", query = "SELECT u FROM UserAudioBookRating u WHERE u.overall = :overall"),
    @NamedQuery(name = "UserAudioBookRating.findByPerformance", query = "SELECT u FROM UserAudioBookRating u WHERE u.performance = :performance"),
    @NamedQuery(name = "UserAudioBookRating.findByStory", query = "SELECT u FROM UserAudioBookRating u WHERE u.story = :story")})
public class UserAudioBookRating implements Serializable {

    private static final long serialVersionUID = 2755218279302523765L;

    @EmbeddedId
    protected UserAudioBookRatingPK userAudioBookRatingPK;

    @Column(name = "OVERALL")
    private String overall;

    @Column(name = "PERFORMANCE")
    private String performance;

    @Column(name = "STORY")
    private String story;

    @JoinColumns({
        @JoinColumn(name = "USER_AUDIO_BOOK_USER_PROFILE_ID", referencedColumnName = "USER_PROFILE_ID", insertable = false, updatable = false),
        @JoinColumn(name = "USER_AUDIO_BOOK_AUDIO_BOOK_ID", referencedColumnName = "AUDIO_BOOK_ID", insertable = false, updatable = false)})
    @OneToOne(optional = false)
    private UserAudioBook userAudioBook;

    public UserAudioBookRating() {
    }

    public UserAudioBookRating(UserAudioBookRatingPK userAudioBookRatingPK) {
        this.userAudioBookRatingPK = userAudioBookRatingPK;
    }

    public UserAudioBookRating(int userAudioBookUserProfileId, int userAudioBookAudioBookId) {
        this.userAudioBookRatingPK = new UserAudioBookRatingPK(userAudioBookUserProfileId, userAudioBookAudioBookId);
    }

    public UserAudioBookRatingPK getUserAudioBookRatingPK() {
        return userAudioBookRatingPK;
    }

    public void setUserAudioBookRatingPK(UserAudioBookRatingPK userAudioBookRatingPK) {
        this.userAudioBookRatingPK = userAudioBookRatingPK;
    }

    public String getOverall() {
        return overall;
    }

    public void setOverall(String overall) {
        this.overall = overall;
    }

    public String getPerformance() {
        return performance;
    }

    public void setPerformance(String performance) {
        this.performance = performance;
    }

    public String getStory() {
        return story;
    }

    public void setStory(String story) {
        this.story = story;
    }

    public UserAudioBook getUserAudioBook() {
        return userAudioBook;
    }

    public void setUserAudioBook(UserAudioBook userAudioBook) {
        this.userAudioBook = userAudioBook;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userAudioBookRatingPK != null ? userAudioBookRatingPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserAudioBookRating)) {
            return false;
        }
        UserAudioBookRating other = (UserAudioBookRating) object;
        if ((this.userAudioBookRatingPK == null && other.userAudioBookRatingPK != null) || (this.userAudioBookRatingPK != null && !this.userAudioBookRatingPK.equals(other.userAudioBookRatingPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.audible.library.domain.beans.UserAudioBookRating[userAudioBookRatingPK=" + userAudioBookRatingPK + "]";
    }

}
